package 面试常见刷题;

public class 单例模式 {
}

class SingleHunger{
    public static SingleHunger singleton = new SingleHunger();
    private SingleHunger(){};
    public SingleHunger getSingleton(){
        return singleton;
    }
}

class SingletonLazy{
    public static volatile SingletonLazy singleton;
    private SingletonLazy(){};
    public SingletonLazy getSingleton(){
        if(singleton!=null) return singleton;
        synchronized (SingletonLazy.class){
            if(singleton==null){
                singleton = new SingletonLazy();
            }
        }
        return singleton;
    }
}

